package com.jf.identity.controller;

import com.jf.identity.entity.Message;
import com.jf.identity.entity.ResponseBean;
import com.jf.identity.exception.ServiceException;
import com.jf.identity.service.MessageService;
import com.jf.identity.util.Params;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by x on 2018/4/12.
 */
@Controller
@RequestMapping("/cdm/")
public class MessageController {
    @Resource
    private MessageService messageService;

    @RequestMapping(value = "get-session-messages")
    @ResponseBody
    public ResponseBean getSessionMessages() {
        return new ResponseBean(messageService.getCommandsBySessionNum());
    }

    @RequestMapping(value = "set-message-read")
    @ResponseBody
    public ResponseBean setMessageRead(@Validated @RequestBody Message message,
                                       BindingResult bindingResult) {
        Params.beanValidate(bindingResult);
        return new ResponseBean(messageService.setCommandRead(message));
    }

    @RequestMapping(value = "set-message-reply")
    @ResponseBody
    public ResponseBean setMessageReply(@Validated @RequestBody Message message,
                                        BindingResult bindingResult) {
        Params.beanValidate(bindingResult);
        return new ResponseBean(messageService.setCommandReply(message));
    }
}
